package com.bdqn.t350.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

import java.util.Arrays;

@Aspect
public class UserServiceLogger {

    Logger logger = Logger.getLogger(UserServiceLogger.class);

    //前置增强  在要执行saveService这个方法之前，先干什么事情
    @Before(value = "execution(public void saveService(..))")
    public void before(JoinPoint joinPoint) {
        logger.info("前置增强。。。。。。。。。。。。。。");
        logger.info("调用" + joinPoint.getTarget() + "的" + joinPoint.getSignature().getName()
                + "方法.方法入参:" + Arrays.toString(joinPoint.getArgs()));

    }

    //后置增强
    @AfterReturning(value = "execution(public void saveService(..))",returning = "result")
    public void afterReturning(JoinPoint joinPoint, Object result) {
        logger.info("后置增强。。。。。。。。。。。。。。");
        logger.info("调用" + joinPoint.getTarget() + "的" + joinPoint.getSignature().getName()
                + "方法.方法返回值" + result);
    }
}
